package cn.findviewbydream.evil.app.service.impl;

import cn.findviewbydream.evil.app.dao.OtherDAO;
import cn.findviewbydream.evil.app.dto.CompleteMealBean;
import cn.findviewbydream.evil.app.service.OtherService;
import cn.findviewbydream.evil.main.entity.OrderEntity;
import cn.findviewbydream.evil.main.entity.OrderItemEntity;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.app.service.impl
 * 时间：17-1-26
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
@Service
public class OtherServiceImpl implements OtherService
{
    private final OtherDAO otherDAO;

    @Autowired
    public OtherServiceImpl(OtherDAO otherDAO) {this.otherDAO = otherDAO;}

    @Nullable
    @Override
    public List<CompleteMealBean> getCompleteMealList()
    {
        List<CompleteMealBean> list = new ArrayList<>();
        CompleteMealBean bean;

        List<OrderEntity> orderList = otherDAO.selectOrderList();
        List<OrderItemEntity> orderItemList;

        for (OrderEntity orderEntity : orderList)
        {
            orderItemList = orderEntity.getOrderItemList();

            if (orderItemList != null && orderItemList.size() > 0)
            {
                for (OrderItemEntity orderItemEntity : orderItemList)
                {
                    if (orderItemEntity.getMealId() != null)
                    {
                        if (orderItemEntity.getMealId().getCookType() != null)
                        {
                            bean = new CompleteMealBean();
                            bean.setOrderId(orderEntity.getOrderId());
                            bean.setSeatId(orderEntity.getSeatId());
                            bean.setWaiter(orderEntity.getWaiter());
                            bean.setCreateDateTime(orderEntity.getCreateDateTime());

                            bean.setOrderItemId(orderItemEntity.getOrderItemId());
                            bean.setMealId(orderItemEntity.getMealId());
                            bean.setMealNum(orderItemEntity.getMealNum());
                            list.add(bean);
                        }
                    }
                }
            }
        }

        return list;
    }
}
